#pragma once
#include "Stdafx.h"
#include "Logger.h"

namespace Pulpy {
	
	template <class T>
	class Vector2D
	{
	private:
		T X;
		T Y;
	public:
		Vector2D(const Vector2D<T> &v): X(v.X), Y(v.Y) { }
		Vector2D(T xin,T yin): X(xin), Y(yin) { }
		Vector2D():X(0),Y(0) { }
		~Vector2D() { X = 0; Y = 0; }

		float getMag() { return sqrt(X*X+Y*Y); }
		T getX() { return X; }
		T getY() { return Y; }
		void Normalize() { X /= getMag(); Y /= getMag(); }

		Vector2D<T> operator* (float mul) {	Vector2D<T> result = *this; result *= mul; return result; } 
		Vector2D<T> operator+ (const Vector2D<T> &v) { Vector2D<T> result = *this; result += v; return result; }
		Vector2D<T> operator- (const Vector2D<T> &v) { Vector2D<T> result = *this; result -= v; return result; }
		Vector2D<T> operator/ (float div) { Vector2D<T> result = *this; result /= div; return result; }
		Vector2D<T> & operator+=(const Vector2D<T> &v) { X += v.X; Y += v.Y; return *this; }
		Vector2D<T> & operator-=(const Vector2D<T> &v) { X -= v.X; Y -= v.Y; return *this; }
		Vector2D<T> & operator*=(float mul) { X *= mul; Y *= mul; return *this; }
		bool operator ==(const Vector2D<T> &v) { return X == v.X && Y == v.Y; }
		Vector2D<T> & operator/=(float div) {
			try
			{
				if(div == 0)
					throw 0;
				X /= div;
				Y /= div;
				return *this;
			}
			catch(int)
			{
				Logger::getInstance().addLog("Division By 0");
				return *this;
			}
		}
		friend std::ostream& operator<<(std::ostream &out, const Vector2D<T> &v)
		{
			out << "(" << v.X << "," << v.Y << ")" << std::endl;
			return out;
		}
	};
}